<!DOCTYPE html>
<html>
<head>
    <title>订单编辑</title>
    <meta http-equiv="Content-Type">
    <meta content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, minimum-scale=1, maximum-scale=1">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="<?php echo URLPRE; ?>static/hm/css/order_detail.css" type="text/css">
    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.11.3/jquery.js
"></script>
    <script type="text/javascript" src="<?php echo URLPRE; ?>static/template/default/mobile/js/layer/layer.js"></script>
    <!-- 日历插件-->
    <link rel="stylesheet" type="text/css"
          href="<?php echo URLPRE; ?>static/template/<?php echo MOBILE_TEMPLATE_NAME ?>/mobile/mobiscroll/css/mobiscroll.css"/>


    <script type="text/javascript"
            src="<?php echo URLPRE; ?>static/template/<?php echo MOBILE_TEMPLATE_NAME ?>/mobile/mobiscroll/js/mobiscroll.js"></script>

    <link href="<?php echo URLPRE;?>static/public/css/font-awesome.min.css" rel="stylesheet" />


    <script type="text/javascript">

        var unit_price = '<?php echo $book_unit_price ? $book_unit_price : 130;?>';
        $(function () {


            $.extend({
                'calculate_order': function () {

                    var woman_num = $('#input_woman_num').val();
                    var male_num = $('#input_male_num').val();
                    var child_num = $('#input_child_number').val();
                    var total_num = parseInt(woman_num) + parseInt(male_num) + parseInt(child_num);

                    var s = new Date($('#start_date').val()), e = new Date($('#end_date').val());

                    var days = parseInt(Math.abs(s - e) / 1000 / 60 / 60 / 24);


                    $('#J_number').text(total_num);

                    var total_price = total_num * unit_price * days;
                    $('.J_order_account').text(total_price);

                }
            })
            $.calculate_order();


            $.extend({
                'order_check_num': function () {

                    var woman_num = $('#input_woman_num').val();
                    var male_num = $('#input_male_num').val();
                    if (parseInt(woman_num) + parseInt(male_num) >= 1) return true;
                    return false;
                }
            })

            $.extend({
                'cal_days': function () {

                    var s = new Date($('#start_date').val()), e = new Date($('#end_date').val());

                    var days = parseInt(Math.abs(s - e) / 1000 / 60 / 60 / 24);

                    if (days > 0) $('#J_day').text(days);
                    return days;
                }
            })


            //  日历切换


            $('#start_date').change(function () {

                var date = $(this).val();
                var month = '';
                var day = '';
                d = new Date(date);
                d = +d + 1000 * 60 * 60 * 24;
                d = new Date(d);

                month = d.getMonth();

                day = d.getDate();

                if ((d.getMonth() + 1).toString().length == 2) {
                    month = (d.getMonth() + 1);
                } else {
                    month = '0' + (d.getMonth() + 1);
                }

                if (d.getDate().toString().length == 2) {
                    day = d.getDate();
                } else {
                    day = '0' + (d.getDate());
                }

                var newdate = d.getFullYear() + "-" + month + "-" + day;


                $('#end_date').val(newdate);
                $('#end_date').mobiscroll().date({
                    theme: 'mobiscroll',
                    lang: 'zh',
                    display: 'center',
                    dateFormat: 'yyyy-mm-dd',
                    min: new Date(d.getFullYear(), d.getMonth(), d.getDate()),
                    max: new Date(2016, 12, 31)
                });

                $.cal_days();
                $.calculate_order();
            })


            $('#end_date').change(function () {

                $.cal_days();
                $.calculate_order();
            })


            $('#start_date').mobiscroll().date({
                theme: 'mobiscroll',
                lang: 'zh',
                display: 'center',
                dateFormat: 'yyyy-mm-dd',
                min: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()),
                max: new Date(2016, 12, 31)
            });

            $('#end_date').mobiscroll().date({
                theme: 'mobiscroll',
                lang: 'zh',
                display: 'center',
                dateFormat: 'yyyy-mm-dd',
                min: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1),
                max: new Date(2016, 12, 31)
            });


            //  修改人数

            $('.input_num').change(function () {

                var value = parseInt($(this).val());

                if ($.order_check_num()) {
                    $(this).val(value);
                } else {
                    $(this).val(1);
                    layer.msg('总人数至少1人!');
                }
                $.calculate_order();

            })

            $('.min_order').click(function () {

                var $input_num = $(this).siblings('input');
                if ($input_num.val() === '') {
                    return;
                }
                var num = parseInt($input_num.val());

                if ($.order_check_num()) {
                    $input_num.val(--num);
                } else {
                    layer.msg('人数至少1人!');
                }
                $.calculate_order();
            });

            $('.plus_order').click(function () {
                var $input_num = $(this).siblings('input');
                if ($input_num.val() === '') {
                    return;
                }
                var num = parseInt($input_num.val());
                $input_num.val(++num);
                $.calculate_order();
            });


            $('.J_submit').on('touchstart', function () {

                if ($('input[name="start_date"]').val() == '0') {
                    layer.msg('请选择入住日期');
                    return false;
                }

                if ($('input[name="end_date"]').val() == '0') {
                    layer.msg('请选择离店日期');
                    return false;
                }


                if ($('input[name="name"]').val().length == 0) {
                    layer.msg('请输入姓名');
                    return false;
                }
                if ($('input[name="phone"]').val().length == 0) {
                    layer.msg('请输入手机号');
                    return false;
                } else {
                    var $val = $("input[name='phone']").val();
                    var length = $val.length;
                    var status = (length == 11 && /^(((17[0-9]{1})|(13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test($val));
                    if (status == false) {
                        layer.msg('请正确填写您的手机号码');
                        return false;
                    }
                }


                var start_date = $('input[name="start_date"]').val();
                var end_date = $('input[name="end_date"]').val();
                var male_num = $('#input_male_num').val();
                var woman_num = $('#input_woman_num').val();
                var name = $('input[name="name"]').val();
                var phone = $('input[name="phone"]').val();
                var note = $('input[name="note"]').val();
                $.post('<?php echo $form_url;?>', {
                    start_date: start_date,
                    end_date: end_date,
                    male_num: male_num,
                    woman_num: woman_num,
                    name: name,
                    note: note,
                    phone: phone
                }, function (data) {
                    layer.msg(data.info);
                    if (data.status == '1') {
                        setTimeout(function () {
                            window.location.href = '<?php echo site_url('hm/order/order_list') ?>';
                        }, 1200);
                    }
                }, 'json')

            });

        })

    </script>

    <style>
        .shopInfo {
            margin-top: 91px;
            padding-bottom: 60px;
            overflow: hidden;
        }

        .orderDetail .ipt-numbers {
            vertical-align: middle;
            width: 2.5rem;
            height: 2rem;
            line-height: 2rem;
            text-align: center;
            color: #005bb5;
            outline: 0;
            border: 1px solid #a6a6a6;
            border-radius: 5px;
        }

        .orderDetail .ipt-numbers+span i{
            font-size: 21px;
            color: #005bb5;
        }

        .orderDetail .in-input-span+span i{
            font-size: 21px;
            color: #005bb5;
        }

        .orderDetail .in-input {
            width: 73%;
            margin-right: -15px;
            border: 0;
            background: 0;
            color: #005bb5;
            outline: 0;
            -webkit-box-shadow: none;
            border-radius: 0;
            text-align: left;
        }

        .orderDetail .in-input-span {
            width: 24%;
            display: inline-block;
        }

    </style>
</head>

<body>
<div class="page active">
    <header class="list-head J_header fixed detail-header">
        <a class="back J_back" href="javascript:history.back();"></a>
        <div class="placeholder"></div>
        <div class="title"><i class="arr-dowm"></i>
            <p class="shop-title">添加订单</p>
           <!-- <div class="shop-item">
                <p style="visibility: hidden" class="shop-sub-title">
                    <span id="J_end"><?php /*echo fdate(date('Y-m-d', strtotime("+1 day"))); */?></span>
                </p>
                <p class="shop-sub-title"><span id="J_number">6</span>人</p>
                <p class="shop-sub-title"><span id="J_day">1</span>天</p>
            </div>-->
        </div>
    </header>

    <div class="shopInfo J_shopInfo">
        <div class="shopDetail orderDetail J_shopDetail ">
            <div class="tip shopdet"><p>
                    <span class="in-input-span">入住日期 :</span>
                    <input type="text" class="in-input" id="start_date" value="<?php echo date('Y-m-d'); ?>" placeholder="请选择入住日期" name="start_date" readonly>
                </p></div>
            <div class="tip shopdet"><p>
                    <span class="in-input-span">离店日期 : </span>
                    <input type="text" class="in-input" id="end_date" value="<?php echo date('Y-m-d', strtotime("+1 day")); ?>" placeholder="请选择入住日期" name="end_date" readonly>
                </p></div>
            <div class="tip shopdet"><p><span class="in-input-span">成人男
                    :</span>
                    <span class="min_order"><i class="fa fa-minus-square"></i> </span>
                    <input type="number" maxlength="3" value="3" class="ipt-numbers" id="input_male_num"  name="male_num">
                    <span class="plus_order"><i class="fa fa-plus-square"></i></span>
                </p></div>
            <div class="tip shopdet"><p><span class="in-input-span">成人女
                    :</span>
                    <span class="min_order"><i class="fa fa-minus-square"></i> </span>
                    <input type="number" maxlength="3" value="3" class="ipt-numbers" id="input_woman_num"
                                                                                             name="woman_num">
                    <span class="plus_order"><i class="fa fa-plus-square"></i></span>
                </p></div>
            <div class="tip shopdet"><p><span class="in-input-span">儿童
                    : </span>
                    <span class="min_order"><i class="fa fa-minus-square"></i> </span>
                    <input type="number" maxlength="0" value="0" class="ipt-numbers" id="input_child_number"
                                                                                             name="child_number">
                    <span class="plus_order"><i class="fa fa-plus-square"></i></span>
                </p></div>

            <div class="tip shopdet"><p><span class="in-input-span">姓名 : </span>
                    <input type="text" class="in-input"   name="name" placeholder="请输入姓名"></p>
            </div>
            <div class="tip shopdet"><p><span class="in-input-span">手机号 :</span>
                    <input type="number" class="in-input" name="phone" placeholder="请输入手机号">
                </p></div>

            <div class="tip shopdet"><p><span class="in-input-span">订单备注 :</span>
                    <input type="text" class="in-input" name="note" placeholder="请输入订单备注">
                </p></div>

        </div>

    </div>


    <input type="hidden" name="order_account" class="J_input_account" value="<?php echo intval($order_info['order_account']); ?>">

    <div class="cart J_cart">
        <div class="cart-cont">
            <div class="btn-box">
                <div class="J_exp brief">
                    <div class="brief-btn"><p class="price">
                            <span>¥</span><span class="J_order_account"></span>
                        </p>
                        <p class="min-del" style="visibility: hidden">
                            外送费￥2.5</p></div>
                </div>
                    <div class="btn J_submit">
                        <div>提交订单</div>
                    </div>

            </div>
        </div>
    </div>


</div>

<div class="foot-bar">
    <ul class="ft">
        <li class="foot_part1 home current"><a href=""><i class="fa fa-home fa-lg"></i><br><span>首页</span></a></li>
        <li class="foot_part2"><a href=""><i class="fa fa-search fa-lg"></i><br><span id="spanid">搜索</span></a></li>
        <li class="foot_part2"><a href="tel:13601468635"><i class="fa fa-phone fa-lg"></i><br><span>电话</span></a></li>
        <li class="foot_part2"><a href=""><i class="fa fa-user fa-lg"></i><br><span>我的</span></a></li>
    </ul>
</div>

</body>
</html>